#pragma once
#include "mkvmuxpin.hpp"
//#include "cstreamio.hpp"
#include <comdef.h>

namespace MkvMux
{

//class CStreamIO;

class Outpin : public Pin
{
    Outpin(const Outpin&);
    Outpin& operator=(const Outpin&);
    
public:

    explicit Outpin(Filter*);
    ~Outpin();
    
    void Init();   //transition from Stopped
    void Final();  //transitio to Stopped
    
    //IUnknown interface:
    
    HRESULT STDMETHODCALLTYPE QueryInterface(const IID&, void**);
    ULONG STDMETHODCALLTYPE AddRef();
    ULONG STDMETHODCALLTYPE Release();
    
    //IPin interface:

    HRESULT STDMETHODCALLTYPE Connect(IPin*, const AM_MEDIA_TYPE*);

    //HRESULT STDMETHODCALLTYPE Disconnect();

    HRESULT STDMETHODCALLTYPE ReceiveConnection( 
        IPin*,
        const AM_MEDIA_TYPE*);
        
    HRESULT STDMETHODCALLTYPE QueryAccept(const AM_MEDIA_TYPE*);

    HRESULT STDMETHODCALLTYPE QueryInternalConnections( 
        IPin**,
        ULONG*);
        
    HRESULT STDMETHODCALLTYPE EndOfStream();
    HRESULT STDMETHODCALLTYPE BeginFlush();    
    HRESULT STDMETHODCALLTYPE EndFlush();
    
    HRESULT STDMETHODCALLTYPE NewSegment( 
        REFERENCE_TIME,
        REFERENCE_TIME,
        double);
        
    //local functions
    
    HRESULT GetDuration(LONGLONG*) const;
    HRESULT GetCurrentPosition(LONGLONG*) const;
    HRESULT GetStopPosition(LONGLONG*) const;

    HRESULT SetPositions( 
        LONGLONG* pCurrPos,
        DWORD dwCurr,
        LONGLONG* pStopPos,
        DWORD dwStop) const;
        
    HRESULT GetPositions( 
        LONGLONG* pCurrPos,
        LONGLONG* pStopPos) const;

    HRESULT GetAvailable( 
        LONGLONG* pEarliest,
        LONGLONG* pLatest) const;

protected:

    virtual HRESULT OnDisconnect();
    
private:

    _COM_SMARTPTR_TYPEDEF(IMemAllocator, __uuidof(IMemAllocator));

    IMemAllocatorPtr m_pAllocator;
    ALLOCATOR_PROPERTIES m_props;

public:

    IStreamPtr m_pStream;
    //CStreamIO m_file;
    
//public:
//
//    HRESULT WriteVideo(IMediaSample*);
//    HRESULT WriteVideoEOS();
//
//    HRESULT WriteAudio(IMediaSample*);
//    HRESULT WriteAudioEOS();
    
};
    
}  //end namespace MkvMux

